home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------
- // ContextMenuAdd.cs ⌐ 2001 by Charles Petzold
- //---------------------------------------------
- using System;
- using System.Drawing;
- using System.Windows.Forms;
-
- class ContextMenuAdd: Form
- {
- MenuItem miColor;
-
- public static void Main()
- {
- Application.Run(new ContextMenuAdd());
- }
- public ContextMenuAdd()
- {
- Text = "Men· contextual utilizando Add";
-
- ContextMenu cm = new ContextMenu();
- EventHandler eh = new EventHandler(MenuColorOnClick);
-
- cm.MenuItems.Add("Negro", eh);
- cm.MenuItems.Add("Azul", eh);
- cm.MenuItems.Add("Verde", eh);
- cm.MenuItems.Add("Celeste", eh);
- cm.MenuItems.Add("Rojo", eh);
- cm.MenuItems.Add("Magenta", eh);
- cm.MenuItems.Add("Amarillo", eh);
- cm.MenuItems.Add("Blanco", eh);
-
- foreach (MenuItem mi in cm.MenuItems)
- mi.RadioCheck = true;
-
- SetStyle(ControlStyles.SupportsTransparentBackColor, true);
-
- miColor = cm.MenuItems[3];
- miColor.Checked = true;
- BackColor = Color.FromName(miColor.Text);
-
- ContextMenu = cm;
- }
- void MenuColorOnClick(object obj, EventArgs ea)
- {
- miColor.Checked = false;
- miColor = (MenuItem) obj;
- miColor.Checked = true;
-
- BackColor = Color.FromName(miColor.Text);
- }
- }
-